from __future__ import annotations

from dataclasses import dataclass


@dataclass
class SectionLength:
    max_length_m: float
    note: str


def compute_max_stringing_section(winch_capacity_kN: float, representative_span_m: float, unit_weight_kN_m: float, block_efficiency: float = 0.9, target_tension_ratio: float = 0.25) -> SectionLength:
    """最大放线区段长度：以张力=重量×代表档距/8 /η 等近似确定可放线长度。

    近似：H ≈ w·l²/(8f)，取目标张力比例 => 反推最大并联跨数与总长。
    这里直接按牵引能力：winch ≥ H/η，求得总线重满足条件的长度。
    """

    effective_capacity = winch_capacity_kN * block_efficiency
    per_span_tension = unit_weight_kN_m * representative_span_m * target_tension_ratio
    n_spans = max(1, int(effective_capacity / max(1e-6, per_span_tension)))
    return SectionLength(max_length_m=n_spans * representative_span_m, note="经验估算，需结合地形与设备摩擦损失")


